package com.u.tool;

import java.sql.ResultSet;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.u.character.*;
import com.u.eventInfo.EventInfo;
import com.u.toolbox.*;

public class IdentityUtil implements Tool {

		public static Role identify(String useracc, String password) throws Exception{
			Role role = null;
			MysqlUtil db = new MysqlUtil();
			try {
				db.connection();
				String sql = "SELECT * FROM y_r.role where user_acc = " + useracc;
				List rolelist = db.query(Role.class, sql);
				if (rolelist.size() == 1) {
					role = (Role) rolelist.get(0);
					if(password.equals(role.getPassword())){
						switch(role.getUsertype()){
						case("manager"): role = new Manager(role); break;
						case("station"): role = new Station(role); break;
						case("processer"): role = new Processer(role); break;
						case("repairer"): role = new Repairer(role); break;
						default: break;
						}
					}else {
						role = null;
					}
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
				db.close();
			}
			return role;
		}
		
		public static void main(String[] args) throws Exception {
			Role role = identify("11000", "111111");
			System.out.println(role.getClass().getSimpleName());	
//			Map<String,EventInfo> map = EventListUtil.getEventList(role, 0);
//			EventInfo eventInfo = map.get("1");
//			System.out.println(eventInfo.getApplier());
		}
		
}
